package com.wyh.lotterysystem.dao.mapper;

import com.wyh.lotterysystem.controller.request.ActivityUser;
import com.wyh.lotterysystem.dao.dataobject.Encrypt;
import com.wyh.lotterysystem.dao.dataobject.UserDo;
import com.wyh.lotterysystem.service.dto.UserListDTO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select count(*) from user where email = #{email}")
    Integer countOfEmail(@Param("email") String email);

    @Select("select count(*) from user where phone_number = #{phoneNumber}")
    Integer countOfPhoneNumber(@Param("phoneNumber") Encrypt phoneNumber);

    @Insert("insert into user values (null,now(),now(),#{userName}," +
            "#{email},#{phoneNumber},#{password},#{identity})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insertUser(UserDo userDo);

    @Select("select * from user where email = #{email}")
    UserDo getUserByMail(@Param("email") String email);

    @Select("select * from user where phone_number = #{phoneNumber}")
    UserDo getUserByPhone(@Param("phoneNumber") Encrypt phoneNumber);

    @Select("<script>" +
            " select * from user" +
            " <if test=\"identity!=null\">" +
            "    where identity = #{identity}" +
            " </if>" +
            " order by id desc" +
            " </script>")
    List<UserDo> getUserList(@Param("identity") String identity);

    @Select("<script>" +
            " select id from user" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<Integer> getUsers(@Param("items") List<Integer> activityUserList);

    @Select("<script>" +
            " select * from user" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<UserDo> batchSelect(@Param("items") List<Integer> winners);
}
